#include "MovePieceNetworkEvent.h"
#include "WellModel.h"

MovePieceNetworkEvent::MovePieceNetworkEvent(Direction direction)
{
    message.header.code = NetworkEvent::CLIENT_MOVE_PIECE;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.direction = direction;
}

MovePieceNetworkEvent::MovePieceNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

MovePieceNetworkEvent::~MovePieceNetworkEvent()
{
}

void* MovePieceNetworkEvent::getMessageBlob()
{
    return &message;
}

size_t MovePieceNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}

void MovePieceNetworkEvent::visitWellModel(WellModel* wellModel) const
{
    int playerId = message.header.playerId;
    switch (message.data.direction)
    {
    case LEFT:
        wellModel->movePieceLeft(playerId);
        break;

    case RIGHT:
        wellModel->movePieceRight(playerId);
        break;

    case DOWN:
        wellModel->movePieceDown(playerId);
        break;

    case INSTANT_DOWN:
        wellModel->movePieceInstantDown(playerId);
        break;

    case ROTATE:
        wellModel->rotatePiece(playerId);
        break;
    }
}
